package cn.xjy.ddlc.context;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import cn.xjy.ddlc.model.Index;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class MatchedIndexItem extends AbstractMatchedItem {
    
    /**
     * 左边
     */
    Index left;
    
    /**
     * 右边
     */
    Index right;
    
    private CompareResult result;
    
    @Override
    public CompareResult compare() {
        if (left == null) {
            result = CompareResult.LEFT_NOT_EXIST;
            return result;
        }
        if (right == null) {
            result = CompareResult.RIGHT_NOT_EXIST;
            return result;
        }
        result = CompareResult.NOT_EQUAL;
        
        if (StringUtils.equals(left.getIndexType(), right.getIndexType())
                && StringUtils.equals(left.getIndexMethod(), left.getIndexMethod())
                && left.getColumns().equals(right.getColumns())) {
            result = CompareResult.EQUAL;
        }
        return result;
    }
    
}
